public class footraceDemo {

    private int turtledistance;//乌龟跑的距离

    private int rabbitdistance;//兔子跑的距离

    class Turtle extends Thread{
        @Override
        public void run() {
            for (int i = 0; i < 800; i++) {
                if(rabbitdistance == 800){
                    System.out.println("兔子已经跑完800米了,兔子赢了!");
                    System.out.println("乌龟才跑了"+turtledistance+"米");
                    break;
                }else{
                    turtledistance+=1;
                    if(turtledistance%100 == 0){
                        try{
                            if(rabbitdistance == 700){
                                System.out.println("乌龟跑了"+turtledistance+"米");
                                System.out.println("兔子跑了700米,此时兔子在睡觉");
                                Thread.sleep(1500);
                            }else {
                                System.out.println("乌龟跑了"+turtledistance+"米");
                                System.out.println("此时兔子跑了"+rabbitdistance+"米");
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }

    class Rabbit extends Thread{
        @Override
        public void run() {
            for (int i = 0; i < 800/5; i++) {
                if(turtledistance == 800){
                    System.out.println("乌龟已经跑完800米了,乌龟赢了!");
                    System.out.println("兔子才跑了"+rabbitdistance+"米");
                    break;
                }else{
                    rabbitdistance+=5;
                    if(rabbitdistance%100==0){
                        try{
                            System.out.println("此时兔子跑了"+rabbitdistance+"米");
                            System.out.println("乌龟跑了"+turtledistance+"米");
                            if(rabbitdistance == 700){
                                System.out.println("兔子觉得自己不会输,所以选择睡觉!");
                                Thread.sleep(10000);
                            }
                        }catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
    public static void main(String[] args) {
        footraceDemo footracedemo = new footraceDemo();
        Turtle turtle = footracedemo.new Turtle();
        Rabbit rabbit = footracedemo.new Rabbit();
        turtle.start();
        rabbit.start();
    }
}
